/*
  Losu Copyright Notice
  --------------------
    Losu is an open source programming language project under the MIT license
  that can be used for both academic and commercial purposes. There are no
  fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies
  as open source software. However, Losu is not public property, and founder
  'chen-chaochen' retains its copyright.

    Losu has been registered with the National Copyright Administration of the
  People's Republic of China, and adopts the MIT license as the copyright
  licensing contract under which the right holder conditionally licenses its
  reproduction, distribution, and modification rights to an unspecified public.

    If you use Losu, please follow the public MIT agreement or choose to enter
  into a dedicated license agreement with us.

  The MIT LICENSE is as follows
  --------------------
  Copyright  2020 - now  chen-chaochen

    Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the “Software”), to
  deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
*/

/*
    This document is part of the Losu Community OSPP - 2024 subject results
  contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to
  the Losu Community.

  The MIT LICENSE is as follows
  --------------------
  Copyright 2024 Dongqiao Huang

    Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the “Software”), to
  deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
 */

#ifndef HPARSER_HH
#define HPARSER_HH

#include "hCodegen.hh"
#include "hLexer.hh"

namespace LosuPreCompiler
{

namespace Parser
{

class hParser
{
public:
  hParser (std::string source, std::string fname); // constructor
  ~hParser ();                                     // destructor
  CodeGen::cgOutput doParse ();                    // parse the source code
private:
  CodeGen::cgType_module p_parModule (); // parse the module
  CodeGen::cgType_submod p_parSubmod (); // parse the sub module
  CodeGen::cgType_func p_parFunc ();     // parse the function
  CodeGen::cgType_number p_parNumber (); // parse the number
  CodeGen::cgType_string p_parString (); // parse the string
  CodeGen::cgType_script p_parScript (); // parse the script
  CodeGen::cgType_object p_parObject (); // parse the object
  CodeGen::cgType_class p_parClass ();   // parse the class
protected:
  Lexer::hLexer *lex;            // lexer
  CodeGen::hCodegen *cgen;       // code generator
  CodeGen::cgType_module module; // module
  std::string fname;             // file name
  std::string expString;         // export string
  void CheckMatch (std::int32_t needed, std::int32_t pre,
                   std::int32_t line); // check the match
  void ParseExp ();
};

} // namespace Parser

} // namespace LosuPreCompiler

#endif